package com.ucode.application.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ucode.springboot.starter.security.entity.UcodeUser;
import com.ucode.springboot.starter.security.service.UcodeUserService;
import com.ucode.sys.model.User;
import com.ucode.sys.service.UserService;

@Service
public class UcodeUserServiceImpl implements UcodeUserService {

    @Autowired
    private UserService userService;
    
    @Override
    public UcodeUser getUser(String username) throws RuntimeException {
        User user = userService.findByMEA(username);
        UcodeUser securityUser = null;
        if(user != null && user.getId() != null){
            /**
             * 账号是否未过期
             */
            boolean accountNonExpired = true;
            /**
             * 账号是否未锁定
             */
            boolean accountNonLocked = true;
            /**
             * 密码是否未过期
             */
            boolean credentialsNonExpired = true;
            securityUser = new UcodeUser(user.getId().toString(), username, user.getPassword(),accountNonExpired,accountNonLocked,credentialsNonExpired);
        }
        return securityUser;
    }

}
